package com.kmproject.haifu.mvp.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.DataHelper;
import com.jess.arms.widget.autolayout.AutoToolbar;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.AppConstant;
import com.kmproject.haifu.app.hfinterface.HousePublishItemClickInterface;
import com.kmproject.haifu.app.hfinterface.HouseReasonRemovalCallBack;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.di.component.DaggerMyStoreComponent;
import com.kmproject.haifu.mvp.contract.MyStoreContract;
import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowBean;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.MemberCenterUserInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.MyStoreMainBean;
import com.kmproject.haifu.mvp.model.entity.beans.MyStoryBean;
import com.kmproject.haifu.mvp.model.entity.resbean.HouseParmarBean;
import com.kmproject.haifu.mvp.presenter.MyStorePresenter;
import com.kmproject.haifu.mvp.ui.adapter.HouseRentingShowListAdapter;
import com.kmproject.haifu.mvp.ui.adapter.MystoryRenthouseAdapter;
import com.kmproject.haifu.mvp.ui.adapter.PopuWindowSelectPxAdapter;
import com.kmproject.haifu.mvp.ui.holder.AddressSelectHolder;
import com.kmproject.haifu.mvp.ui.holder.PxSelectHolder;
import com.kmproject.haifu.mvp.ui.holder.SxSelectHolderNew;
import com.kmproject.haifu.mvp.ui.holder.ZjSelectHolder;
import com.kmproject.haifu.mvp.ui.widget.ExpandableTextView;
import com.kmproject.haifu.mvp.ui.widget.RoundCornerImageView;
import com.kmproject.haifu.mvp.ui.widget.ScaleTransitionPagerTitleView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.yyydjk.library.DropDownMenu;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 07/25/2019 13:45
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class MyStoreActivity extends BaseActivity<MyStorePresenter> implements MyStoreContract.View {

    @BindView(R.id.toolbar_backImg)
    ImageView toolbarBackImg;
    @BindView(R.id.toolbar_back)
    RelativeLayout toolbarBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.back_right_icon)
    ImageView backRightIcon;
    @BindView(R.id.back_right_txt)
    TextView backRightTxt;
    @BindView(R.id.toolbar_right)
    RelativeLayout toolbarRight;
    @BindView(R.id.toolbar)
    AutoToolbar toolbar;

    @BindView(R.id.mystore_head_headImg)
    RoundCornerImageView mystoreHeadHeadImg;
    @BindView(R.id.mystore_head_name)
    TextView mystoreHeadName;
    @BindView(R.id.mystore_head_dpdj_img)
    TextView mystoreHeadDpdjImg;
    @BindView(R.id.mystore_head_hydj_img)
    ImageView mystoreHeadHydjImg;
    @BindView(R.id.mystore_head_togoUpdate)
    TextView mystoreHeadTogoUpdate;
    @BindView(R.id.mystore_head_dpgl_txt)
    TextView mystoreHeadDpglTxt;
    @BindView(R.id.mystore_head_fs_txt)
    TextView mystoreHeadFsTxt;
    @BindView(R.id.mystore_head_fs_lay)
    LinearLayout mystoreHeadFsLay;
    @BindView(R.id.mystore_head_pf_txt)
    TextView mystoreHeadPfTxt;
    @BindView(R.id.mystore_head_pf_lay)
    LinearLayout mystoreHeadPfLay;
    @BindView(R.id.mystore_head_lll_txt)
    TextView mystoreHeadLllTxt;
    @BindView(R.id.mystore_head_lll_lay)
    LinearLayout mystoreHeadLllLay;
    @BindView(R.id.toolbar_layout)
    CollapsingToolbarLayout toolbarLayout;
    @BindView(R.id.mystore_story_indicator)
    MagicIndicator mystoreStoryIndicator;
    @BindView(R.id.mystore_head_typeselect_RadioButton1)
    RadioButton mystoreHeadTypeselectRadioButton1;
    @BindView(R.id.mystore_head_typeselect_RadioButton2)
    RadioButton mystoreHeadTypeselectRadioButton2;
    @BindView(R.id.mystore_head_typeselect_RadioGroup)
    RadioGroup mystoreHeadTypeselectRadioGroup;
    @BindView(R.id.app_bar)
    AppBarLayout appBar;

    @BindView(R.id.mystore_head_bottom_fbfy_txt)
    TextView mystoreHeadBottomFbfyTxt;
    @BindView(R.id.mystore_head_bottom_ckxjfy_txt)
    TextView mystoreHeadBottomCkxjfyTxt;
    DropDownMenu dropDownMenu;
    List<String> titles = new ArrayList<>();
    MemberCenterUserInfoBean memberCenterUserInfoBean;//用户会员信息
    MyStoreMainBean mmyStoreMainBean;//当前店铺信息
    @BindView(R.id.ll_head_type_select_layout)
    LinearLayout llHeadTypeSelectLayout;

    @BindView(R.id.dropdownmenu_layout_RelativeLayout)
    RelativeLayout dropdownmenuLayoutRelativeLayout;

    @BindView(R.id.mystore_head_bottom_root_lay)
    LinearLayout mystoreHeadBottomRootLay;
    @BindView(R.id.mystore_head_lll_gz)
    TextView mystoreHeadLllGz;
    @BindView(R.id.mystore_head_gz_lay)
    LinearLayout mystoreHeadGzLay;


    //    private MyStoryBean.ResultBean myStoryBeanResultBean;
    private LinearLayout mystory_content_lay;
    private List<HousePayWayBean> mhousePayWayBeans;//房屋类型，居民住宅、商品房屋
    private List<HousePayWayBean> mhousePayWayBeansXjTsY;//下架提示语
    private MystoryRenthouseAdapter mystoryRenthouseAdapter;
    private HouseParmarBean houseParmarBean = new HouseParmarBean();//查询条件对象
    private List<HouseRentListShowInfoBean> mhouseRentListShowInfoBeans=new ArrayList<>();//当前店铺的信息
    private SmartRefreshLayout refreshLayout;
    //======================================================================筛选相关
    private String headers[] = {"位置", "租金", "筛选", ""};
    private List<View> popupViews = new ArrayList<>();
    private View addressView, zuJinView, shaiXuanViewNew, paiXuView, contentView;
    Map<String, Object> shaiXuanDatas = new HashMap<>();//临时保存筛选条件
    private List<HousePayWayBean> addressSelectData, czyqAndfytsSelectData, zjqjHousePayWayBeans, addRessHousePayWayBeansDis;
    private AddressSelectHolder addressSelectHolder;
    private ZjSelectHolder zjSelectHolder;
    private PxSelectHolder pxSelectHolder;
    private SxSelectHolderNew sxSelectHolderNew;
    private HousePayWayBean addressSelectOne;//选择地址，被选中的那一个
    private HousePayWayBean addressSelectFj;//选择附近 和选择地址互斥，
    private String msamllPrice = "", mbigPrice = "";//选择的最小最大价格
    private String pxSelect = "";//排序选中的条件，默认的是空的
    //用户进来看到信息展示adapter
    private HouseRentingShowListAdapter contentAdapter;
    private boolean isShowMyStore = true;//是否显示我的店铺
    private List<HouseRentListShowBean> mhouseRentListShowBeans=new ArrayList<>();//用户看到的当前店铺的信息

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerMyStoreComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_my_store; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        Drawable drawableLeft = getResources().getDrawable(
                R.drawable.store_swch_icon);
        backRightTxt.setCompoundDrawablesWithIntrinsicBounds(drawableLeft,
                null, null, null);
        backRightTxt.setCompoundDrawablePadding(5);
        mPresenter.getMemberLevelByUser();//获取会员信息
        isShowMyStore = getIntent().hasExtra("MyStoryBeanResultBean");
        if (!isShowMyStore) {
            //用户从租房详情跳转过来的隐藏底部按钮
            mystoreHeadBottomRootLay.setVisibility(View.GONE);
            mystoreHeadTogoUpdate.setVisibility(View.GONE);
            mystoreHeadDpglTxt.setVisibility(View.INVISIBLE);
            mystoreHeadFsLay.setEnabled(false);//不能点击
            backRightTxt.setVisibility(View.INVISIBLE);
//            mystoreHeadGzLay.setVisibility(View.VISIBLE);
            mystoreHeadLllGz.setVisibility(View.VISIBLE);
            mystoreHeadDpglTxt.setVisibility(View.GONE);
//            dasd
            toolbarTitle.setTextColor(ArmsUtils.getColor(this, R.color.white));
            toolbar.setBackgroundColor(ArmsUtils.getColor(this, R.color.white));
            toolbarBackImg.setImageResource(R.drawable.black_back);
            backRightTxt.setTextColor(ArmsUtils.getColor(this, R.color.white));

        } else {
            //我的店铺
            mystoreHeadLllGz.setVisibility(View.GONE);
            mystoreHeadDpglTxt.setVisibility(View.VISIBLE);
            toolbarTitle.setTextColor(ArmsUtils.getColor(this, R.color.white));
            toolbar.setBackgroundColor(ArmsUtils.getColor(this, R.color.color_3F3F4B));
            toolbarBackImg.setImageResource(R.drawable.member_center_main_back_img);
            backRightTxt.setTextColor(ArmsUtils.getColor(this, R.color.white));
            backRightTxt.setText(ArmsUtils.getString(this, R.string.mystory_dpqh));
        }
        HousePayWayBean housePayWayBean= DataHelper.getDeviceData(this,AppConstant.user_default_select_area);
        if (housePayWayBean!=null)
        {
            addressSelectOne=housePayWayBean;//默认选中的地址
            headers[0]= addressSelectOne.getName();
        }
        backRightTxt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                killMyself();
            }
        });
        if (getIntent().hasExtra("userId"))
        {
            houseParmarBean.setUserId(getIntent().getStringExtra("userId"));
        }
        if (getIntent().hasExtra("userStoreId"))
        {
            houseParmarBean.setUserStoreId(getIntent().getStringExtra("userStoreId"));
        }

        if (isShowMyStore) {
            mPresenter.dictList(Api.LOWER_SHELF_REASON, "");//获取下架提示语
        }

        mPresenter.dictList(Api.HOUSE_CATEGORY, "");//获取类别居民住宅和商业用地
        mystoreHeadTypeselectRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.mystore_head_typeselect_RadioButton1:
                        if (mhousePayWayBeans == null) {
                            showMessage("未获取到类型");
                            return;
                        }
                        if (!mhouseRentListShowInfoBeans.isEmpty()) {
                            mhouseRentListShowInfoBeans.clear();
                        }
                        if (!mhouseRentListShowBeans .isEmpty()) {
                            mhouseRentListShowBeans.clear();
                        }
                        if (isShowMyStore) {
                            mystoryRenthouseAdapter.setNewData(null);
                        } else {
                            contentAdapter.setNewData(null);
                        }

                        houseParmarBean.setPage(1);
                        houseParmarBean.setHouseCategory(mhousePayWayBeans.get(0).getCategory());
                        mPresenter.listHouseRentByStore(isShowMyStore, houseParmarBean);
                        mPresenter.getQueryConditionTree(mhousePayWayBeans.get(0).getCategory(), "", shaiXuanDatas.containsKey(mhousePayWayBeans.get(0).getCategory()) ? (List<HousePayWayBean>) shaiXuanDatas.get(mhousePayWayBeans.get(0).getCategory()) : null);//获取杀下拉条件

                        break;
                    case R.id.mystore_head_typeselect_RadioButton2:
                        if (mhousePayWayBeans == null) {
                            showMessage("未获取到类型");
                            return;
                        }
                        if (!mhouseRentListShowInfoBeans .isEmpty()) {
                            mhouseRentListShowInfoBeans.clear();
                        }
                        if (!mhouseRentListShowBeans .isEmpty()) {
                            mhouseRentListShowBeans.clear();
                        }
                        if (isShowMyStore) {
                            mystoryRenthouseAdapter.setNewData(null);
                        } else {
                            contentAdapter.setNewData(null);
                        }
                        houseParmarBean.setPage(1);
                        houseParmarBean.setHouseCategory(mhousePayWayBeans.get(1).getCategory());
                        mPresenter.listHouseRentByStore(isShowMyStore, houseParmarBean);
                        mPresenter.getQueryConditionTree(mhousePayWayBeans.get(1).getCategory(), "", shaiXuanDatas.containsKey(mhousePayWayBeans.get(1).getCategory()) ? (List<HousePayWayBean>) shaiXuanDatas.get(mhousePayWayBeans.get(1).getCategory()) : null);//获取杀下拉条件

                        break;
                }

            }
        });
        initDropDownMenu();
        mPresenter.getHousePayWayBean(Api.DISTANCE, "", addRessHousePayWayBeansDis);//获取筛选条件距离
        mPresenter.getHousePayWayBean(Api.HOUSE_AREA, "", addressSelectData);//获取区域
        mPresenter.getHousePayWayBean(Api.MONTH_RENT, "", zjqjHousePayWayBeans);//租金区间
    }

    @Override
    public void getQueryConditionTreeSuccess(String houseCategory, List<HousePayWayBean> housePayWayBeans) {
        //筛选条件会员
        shaiXuanDatas.put(houseCategory, housePayWayBeans);
        if (sxSelectHolderNew == null) {
            sxSelectHolderNew = new SxSelectHolderNew(this, shaiXuanViewNew, new SxSelectHolderNew.selectCallBack() {
                @Override
                public void callBack(HousePayWayBean housePayWayBean) {
                    dropDownMenu.closeMenu();
                    if (!mhouseRentListShowInfoBeans .isEmpty()) {
                        mhouseRentListShowInfoBeans.clear();
                    }
                    if (!mhouseRentListShowBeans.isEmpty()) {
                        mhouseRentListShowBeans.clear();
                    }
                    //筛选回调
                    mPresenter.listHouseRentByStore(isShowMyStore, mPresenter.setParmat(houseParmarBean, housePayWayBean));

                }
            });
        }
        sxSelectHolderNew.initShow(this, new HousePayWayBean("store"), housePayWayBeans);
    }


    /**
     * 初始化弹出控件
     */
    public void initDropDownMenu() {
        dropDownMenu = (DropDownMenu) findViewById(R.id.dropDownMenu);
        dropDownMenu.setMenuHeighPercent(0.5f);
        addressView = LayoutInflater.from(this).inflate(R.layout.popuwindows_seelct_adress, null);
        zuJinView = LayoutInflater.from(this).inflate(R.layout.popuwindows_seelct_zj, null);
        shaiXuanViewNew = LayoutInflater.from(this).inflate(R.layout.popuwindows_seelct_sx_new, null);
        paiXuView = LayoutInflater.from(this).inflate(R.layout.popuwindows_seelct_px, null);
        popupViews.add(addressView);
        popupViews.add(zuJinView);
        popupViews.add(shaiXuanViewNew);
        popupViews.add(paiXuView);
        contentView = LayoutInflater.from(this).inflate(R.layout.mystory_content, null);
        mystory_content_lay = contentView.findViewById(R.id.mystory_content_lay);
        dropDownMenu.setMenuSelectedImgIcon(R.drawable.houserentingshow_selection_select_tj);
        dropDownMenu.setMenuUnselectedImgIcon(R.drawable.houserentingshow_selection_noselect_tj);
        dropDownMenu.setDropDownMenu(Arrays.asList(headers), popupViews, contentView);
        dropDownMenu.setClickBtn(new DropDownMenu.ClickBtn() {
            @Override
            public void clikCallBack(View view) {
                if (view instanceof TextView) {
                    Log.i("######", ((TextView) view).getText().toString());
                }
            }
        });
        initPaiXuPopuwindows();
    }

    /**
     * 初始化排序弹框
     */
    private void initPaiXuPopuwindows() {
        if (pxSelectHolder == null) {
            pxSelectHolder = new PxSelectHolder(this, paiXuView, new PopuWindowSelectPxAdapter.BtncliickCallBack() {
                @Override
                public void callBack(int index, Object content) {
                    if (!mhouseRentListShowInfoBeans .isEmpty()) {
                        mhouseRentListShowInfoBeans.clear();
                    }
                    if (!mhouseRentListShowBeans .isEmpty()) {
                        mhouseRentListShowBeans.clear();
                    }
                    pxSelect = (String) content;
                    houseParmarBean.setOrderByFiled(pxSelect);
                    houseParmarBean.setPage(1);
                    mPresenter.listHouseRentByStore(isShowMyStore, houseParmarBean);
                    dropDownMenu.closeMenu();
                }
            });
        }

    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.getStoreInfo(getIntent().getStringExtra("userStoreId"));
    }

    @Override
    public void showLoading() {
        loadingDialog.show();
    }

    @Override
    public void hideLoading() {
        loadingDialog.dismiss();
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    //    Api.STORE_TYPE
    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.mystore_head_lll_gz, R.id.mystore_head_fs_lay, R.id.mystore_head_bottom_ckxjfy_txt, R.id.mystore_head_bottom_fbfy_txt, R.id.mystore_head_togoUpdate, R.id.mystore_head_dpgl_txt})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.mystore_head_lll_gz:
                if (mmyStoreMainBean == null) {
                    showMessage("未获取到店铺信息");
                    return;
                }
                if (!AppUtil.userIsLogin(this)) {
                    ArmsUtils.startActivity(UserSetingActivity.class);
                    showMessage("请先登录");
                    return;
                }
                if (mmyStoreMainBean.getIsAttention() == 0) {
                    mPresenter.userAttentionAdd(mmyStoreMainBean.getStoreId());
                } else {
                    //取消关注
                    mPresenter.userAttentionCancel(mmyStoreMainBean.getStoreId());
                }

                break;
            case R.id.mystore_head_fs_lay:
                //粉丝
                break;
            case R.id.mystore_head_bottom_fbfy_txt:
                Intent intent1 = new Intent(MyStoreActivity.this, HousePublishMainActivity.class);
                intent1.putExtra("MyStoryBeanResultBean", (MyStoryBean.ResultBean) getIntent().getSerializableExtra("myStoryBeanResultBean"));
                //跳转到发布模块
                ArmsUtils.startActivityForResult(intent1, 1001);
                break;
            case R.id.mystore_head_bottom_ckxjfy_txt:
                if (mmyStoreMainBean == null) {
                    showMessage("未获取到店铺信息，请重试");
                    return;
                }
                if (mhousePayWayBeans == null || mhousePayWayBeans.isEmpty()) {
                    showMessage("未获取到类型信息，请重试");
                    return;
                }
                Intent intent3 = new Intent(MyStoreActivity.this, MyStoreLookObtainedActivity.class);
                intent3.putExtra("MyStoreMainBean", mmyStoreMainBean);
                intent3.putExtra("HousePayWayBean", (ArrayList<? extends Serializable>) mhousePayWayBeans);
//                intent3.getSerializableExtra()
                startActivity(intent3);
                break;
            case R.id.mystore_head_togoUpdate:
                //去升级
                Intent intent = new Intent(MyStoreActivity.this, MemberCenterUpdateLevelActivity.class);
                intent.putExtra("MemberCenterUserInfoBean", memberCenterUserInfoBean);
                startActivity(intent);
                break;
            case R.id.mystore_head_dpgl_txt:
                Intent intent2 = new Intent(MyStoreActivity.this, MyStoryAddStoryActivity.class);
                intent2.putExtra("MyStoreMainBean", mmyStoreMainBean);
                startActivityForResult(intent2, 1002);
                break;

        }
    }

    @Override
    public void getHouseArea(List<HousePayWayBean> housePayWayBeans) {

    }

    @Override
    public void dictListSuccess(List<HousePayWayBean> housePayWayBeans) {
        if (housePayWayBeans == null || housePayWayBeans.isEmpty()) {
            return;
        }
        switch (housePayWayBeans.get(0).getValue()) {
            case Api.HOUSE_CATEGORY:
                mhousePayWayBeans = housePayWayBeans;
                if (housePayWayBeans != null) {
                    houseParmarBean.setHouseCategory(housePayWayBeans.get(0).getCategory());
                    mPresenter.getQueryConditionTree(mhousePayWayBeans.get(0).getCategory(), "", shaiXuanDatas.containsKey(mhousePayWayBeans.get(0).getCategory()) ? (List<HousePayWayBean>) shaiXuanDatas.get(mhousePayWayBeans.get(0).getCategory()) : null);//获取杀下拉条件
                    contralShow(0);
                }
                break;

            case Api.LOWER_SHELF_REASON:
                //下架提示语
                mhousePayWayBeansXjTsY = housePayWayBeans;
                if (mystoryRenthouseAdapter != null) {
                    mystoryRenthouseAdapter.setNewData(mhouseRentListShowInfoBeans);
                }

                break;
        }

    }

    @Override
    public void getStoreInfoSuccess(MyStoreMainBean myStoreMainBean) {
        if (!isShowMyStore) {
            toolbarTitle.setText(myStoreMainBean.getStoreTypeName());
        }
        houseParmarBean.setUserId(myStoreMainBean.getUserId());//设置userid
        mmyStoreMainBean = myStoreMainBean;
        getMglideImage().loadImage(this, ImageConfigImpl.builder().url(myStoreMainBean.getStoreLogo())
                .imageView(mystoreHeadHeadImg.setmBorderRadius(10))
                .build());
        mystoreHeadName.setText(myStoreMainBean.getStoreName());
        mystoreHeadDpdjImg.setText(myStoreMainBean.getStoreRankName());
        if (!isShowMyStore) {
            if (myStoreMainBean.getIsAttention() == 0) {
                //未关注
                mystoreHeadLllGz.setText(ArmsUtils.getString(this, R.string.follow_add));
                mystoreHeadLllGz.setTextColor(ArmsUtils.getColor(this, R.color.color_191919));
                mystoreHeadLllGz.setBackgroundResource(R.drawable.button_yellow_bg);
            } else {
                //已关注
                mystoreHeadLllGz.setText(ArmsUtils.getString(this, R.string.is_followed));
                mystoreHeadLllGz.setTextColor(ArmsUtils.getColor(this, R.color.white));
                mystoreHeadLllGz.setBackgroundResource(R.drawable.button_gray_bg);
            }

        }
        mystoreHeadFsTxt.setText(myStoreMainBean.getAttentionCount() + "");
        mystoreHeadPfTxt.setText(myStoreMainBean.getScore() + "");
        mystoreHeadLllTxt.setText(myStoreMainBean.getViewCount() + "");
        titles.clear();

        titles.add("租房（" + myStoreMainBean.getHouseRentCount() + "）");
        titles.add("店铺信息");
        CommonNavigator commonNavigator = new CommonNavigator(this);
        commonNavigator.setAdapter(new CommonNavigatorAdapter() {
            @Override
            public int getCount() {
                return titles.size();
            }

            @Override
            public IPagerTitleView getTitleView(Context context, final int index) {

                SimplePagerTitleView simplePagerTitleView = new ScaleTransitionPagerTitleView(context);
                simplePagerTitleView.setText(titles.get(index));
                DisplayMetrics dm = getResources().getDisplayMetrics();
                simplePagerTitleView.setWidth((dm.widthPixels) / 2);

                simplePagerTitleView.setTextSize(16);
                simplePagerTitleView.setNormalColor(getResources().getColor(R.color.color_191919));
                simplePagerTitleView.setSelectedColor(getResources().getColor(R.color.color_191919));
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//                layoutParams.setMargins(15, 0, 5, 0);//4个参数按顺序分别是左上右下
                simplePagerTitleView.setLayoutParams(layoutParams);
                simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mystoreStoryIndicator.onPageSelected(index);
                        commonNavigator.getAdapter().notifyDataSetChanged();
                        contralShow(index);
                    }
                });

                return simplePagerTitleView;
            }

            @Override
            public IPagerIndicator getIndicator(Context context) {
                LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context);
                linePagerIndicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT);
                linePagerIndicator.setLineHeight(8.0f);
                linePagerIndicator.setColors(ArmsUtils.getColor(MyStoreActivity.this, R.color.color_F9D35A));

                return linePagerIndicator;
            }

            @Override
            public float getTitleWeight(Context context, int index) {
                return 1.0f;
            }

        });
        mystoreStoryIndicator.setNavigator(commonNavigator);
    }

    @Override
    public void listHouseRentByStoreSuccess(List<HouseRentListShowInfoBean> houseRentListShowInfoBeans) {
        if (refreshLayout != null) {
            refreshLayout.finishLoadMore();
        }
        if (houseRentListShowInfoBeans == null || houseRentListShowInfoBeans.isEmpty()) {
            mystoryRenthouseAdapter.setNewData(mhouseRentListShowInfoBeans);
            mystoryRenthouseAdapter.setEmptyView(AppUtil.setEmptyView(MyStoreActivity.this, "未查询到信息", "", null, true));
            refreshLayout.setEnableLoadMore(false);
            return;
        }
        if (mhouseRentListShowInfoBeans == null) {
            mhouseRentListShowInfoBeans = new ArrayList<>();
        }
        if (houseRentListShowInfoBeans.size() < AppConstant.pageSize) {
            refreshLayout.setEnableLoadMore(false);
        }else {
            refreshLayout.setEnableLoadMore(true);
        }
        if (mhouseRentListShowInfoBeans != null && !mhouseRentListShowInfoBeans.isEmpty()) {
            mystoryRenthouseAdapter.addData(houseRentListShowInfoBeans);
        } else {
            mystoryRenthouseAdapter.setNewData(houseRentListShowInfoBeans);
        }
        mhouseRentListShowInfoBeans.addAll(houseRentListShowInfoBeans);
    }

    @Override
    public void getHouseRentListSuccess(ResultBean<List<HouseRentListShowBean>> houseRentListShowBeans) {
        refreshLayout.finishLoadMore();
        if (houseRentListShowBeans == null || houseRentListShowBeans.getData() == null || houseRentListShowBeans.getData().isEmpty()) {
            if (contentAdapter.getData() == null || contentAdapter.getData().isEmpty()) {
                //第一次就没有数据
                contentAdapter.setEmptyView(AppUtil.setEmptyView(MyStoreActivity.this, "没有租房信息！", "", null, true));
//                contentAdapter.setEmptyView(R.layout.empty_view);
            }
            refreshLayout.setEnableLoadMore(false);//不能刷新了
            return;
        }

        if (houseRentListShowBeans.getData().size() < AppConstant.pageSize || Integer.parseInt(houseRentListShowBeans.getExtra().getPage().getPages()) == (houseParmarBean.getPage() + 1)) {
            //如果当前获取的数据的条数小于当前每页显示条数，不能刷新了
            refreshLayout.setEnableLoadMore(false);//不能刷新了
        }else {
            refreshLayout.setEnableLoadMore(true);//不能刷新了
        }
        houseParmarBean.setPage(houseRentListShowBeans.getExtra().getPage().getPage() + 1);
        if (contentAdapter.getData() == null || contentAdapter.getData().isEmpty()) {
            contentAdapter.setNewData(houseRentListShowBeans.getData());
        } else {
            contentAdapter.addData(houseRentListShowBeans.getData());
        }
        if (mhouseRentListShowBeans == null) {
            mhouseRentListShowBeans = new ArrayList<>();
        }
        mhouseRentListShowBeans.addAll(houseRentListShowBeans.getData());
    }

    @Override
    public void userAttentionAddSuccess(ResultBean resultBean) {
        //关注成功
        //已关注
        mmyStoreMainBean.setIsAttention(1);
        mystoreHeadLllGz.setText(ArmsUtils.getString(this, R.string.is_followed));
        mystoreHeadLllGz.setTextColor(ArmsUtils.getColor(this, R.color.white));
        mystoreHeadLllGz.setBackgroundResource(R.drawable.button_gray_bg);

    }

    @Override
    public void userAttentionCancelSuccess(ResultBean resultBean) {
        //未关注
        mmyStoreMainBean.setIsAttention(0);
        mystoreHeadLllGz.setText(ArmsUtils.getString(this, R.string.follow_add));
        mystoreHeadLllGz.setTextColor(ArmsUtils.getColor(this, R.color.color_191919));
        mystoreHeadLllGz.setBackgroundResource(R.drawable.button_yellow_bg);
    }

    @Override
    public void removeHouseRentSuccess() {
        //删除成功刷新数据
        if (!mhouseRentListShowInfoBeans.isEmpty()) {
            mhouseRentListShowInfoBeans.clear();
        }
        houseParmarBean.setPage(1);
        mPresenter.listHouseRentByStore(isShowMyStore, houseParmarBean);
    }

    @Override
    public void lowerShelfHouseRentSuccess() {
        //下架成功刷新数据
        if (!mhouseRentListShowInfoBeans .isEmpty()) {
            mhouseRentListShowInfoBeans.clear();
        }
        houseParmarBean.setPage(1);
        mPresenter.listHouseRentByStore(isShowMyStore, houseParmarBean);
    }

    @Override
    public void getHousePayWayBeanSuccess(String value, List<HousePayWayBean> housePayWayBeans) {

        switch (value) {

            case Api.DISTANCE:
                addRessHousePayWayBeansDis = housePayWayBeans;
                break;
            case Api.MONTH_RENT:
                zjqjHousePayWayBeans = housePayWayBeans;
                if (zjSelectHolder == null) {
                    zjSelectHolder = new ZjSelectHolder(this, housePayWayBeans, zuJinView, new ZjSelectHolder.PriceCallback() {
                        @Override
                        public void callBack(String samllPrice, String bigPrice) {
                            msamllPrice = samllPrice;
                            mbigPrice = bigPrice;
                            houseParmarBean.setPage(1);
                            if (TextUtils.isEmpty(samllPrice)) {
                                houseParmarBean.setMinMonthRent(null);
                            } else {
                                houseParmarBean.setMinMonthRent(samllPrice);
                            }
                            if (TextUtils.isEmpty(bigPrice)) {
                                houseParmarBean.setMaxMonthRent(null);
                            } else {
                                houseParmarBean.setMaxMonthRent(mbigPrice);
                            }
                            if (!mhouseRentListShowInfoBeans.isEmpty()) {
                                mhouseRentListShowInfoBeans.clear();
                            }
                            if (!mhouseRentListShowBeans.isEmpty()) {
                                mhouseRentListShowBeans.clear();
                            }
                            mPresenter.listHouseRentByStore(isShowMyStore, houseParmarBean);
                            dropDownMenu.closeMenu();
                        }
                    });
                }
                break;
            case Api.HOUSE_AREA:
                this.addressSelectData = housePayWayBeans;
                if (addressSelectHolder == null && housePayWayBeans != null && !housePayWayBeans.isEmpty() && addRessHousePayWayBeansDis != null) {
                    //请求到地址后默认加载数据

                    addressSelectHolder = new AddressSelectHolder(this, addressView, housePayWayBeans, addRessHousePayWayBeansDis,addressSelectOne);
                    addressSelectHolder.init(new AddressSelectHolder.SelectAddressCallBack() {
                        @Override
                        public void callBack(String type, int index, Object o) {
                            mhouseRentListShowInfoBeans.clear();
                            mhouseRentListShowBeans.clear();
                            if (index == 0) {
                                dropDownMenu.setTabText("不限");
                                houseParmarBean.setDis(null);
                                houseParmarBean.setHouseArea(null);
                                houseParmarBean.setLgt(null);
                                houseParmarBean.setLat(null);
                                houseParmarBean.setPage(1);
                                mPresenter.listHouseRentByStore(isShowMyStore, houseParmarBean);
                                dropDownMenu.closeMenu();
                                return;
                            }
                            if (type.equals("区域")) {
                                addressSelectOne = (HousePayWayBean) o;
                                addressSelectFj = null;
                                dropDownMenu.setTabText(type.equals("区域") ? ((HousePayWayBean) o).getName() : type);
                                houseParmarBean.setDis(null);
                                houseParmarBean.setHouseArea(addressSelectOne.getDictId());
                                houseParmarBean.setLgt(null);
                                houseParmarBean.setLat(null);

                            } else {
                                dropDownMenu.setTabText(type.equals("区域") ? ((HousePayWayBean) o).getName() : type);
                                addressSelectOne = null;
                                addressSelectFj = (HousePayWayBean) o;
                                if (!addressSelectFj.getName().equals("不限")) {
                                    houseParmarBean.setDis(addressSelectFj.getCategory());
                                } else {
                                    houseParmarBean.setDis(null);
                                }
                                houseParmarBean.setHouseArea(null);
                                Location location = startLocation();
                                if (location != null) {
                                    houseParmarBean.setLgt(String.valueOf(location.getLongitude()));
                                    houseParmarBean.setLat(String.valueOf(location.getLatitude()));

                                } else {
                                    showMessage("未获取到经纬度信息");
                                }
                                //必须设置经纬度
                            }
                            mPresenter.listHouseRentByStore(isShowMyStore, houseParmarBean);
                            dropDownMenu.closeMenu();
                        }
                    });
                }
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1002) {
            //从店铺编辑回来的刷新数据
            mPresenter.getStoreInfo(getIntent().getStringExtra("userStoreId"));
        }
    }

    /**
     * 控制内容的显示，并填充内容
     *
     * @param index
     */
    public void contralShow(int index) {
        switch (index) {
            case 0:
                llHeadTypeSelectLayout.setVisibility(View.VISIBLE);
                dropDownMenu.visible(true);
                if (mystory_content_lay.getChildCount() > 0) {
                    mystory_content_lay.removeAllViews();
                }
                View view1 = LayoutInflater.from(this).inflate(R.layout.mystory_renthouse_lay, null);
                mystory_content_lay.addView(view1);
                RecyclerView recyclerView = view1.findViewById(R.id.mystory_renthouse_lay_RecyclerView);
                refreshLayout = view1.findViewById(R.id.refreshLayout);

                recyclerView.setLayoutManager(new LinearLayoutManager(MyStoreActivity.this));

                if (isShowMyStore) {
                    mystoryRenthouseAdapter = new MystoryRenthouseAdapter(new HousePublishItemClickInterface() {
                        @Override
                        public void callBack(HouseRentListShowInfoBean houseRentListShowInfoBean, HousePayWayBean housePayWayBean, String type) {
                            if (type.equals("Obtained")) {
                                //下架  大大
                                mPresenter.houseReasonRemoval(MyStoreActivity.this, llHeadTypeSelectLayout, mhousePayWayBeansXjTsY, new HouseReasonRemovalCallBack() {
                                    @Override
                                    public void callBack(HousePayWayBean housePayWayBean) {
                                        if (housePayWayBean != null) {
                                            mPresenter.lowerShelfHouseRent(houseRentListShowInfoBean.getRentId(), housePayWayBean.getDictId());
                                        }
                                    }
                                });
                            } else if (type.equals("del")) {
                                //删除
                                mPresenter.removeHouseRent(houseRentListShowInfoBean.getRentId());
                            }
                        }
                    }, new ArrayList<>(), mhousePayWayBeansXjTsY);
                    recyclerView.setAdapter(mystoryRenthouseAdapter);
                    mystoryRenthouseAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_RIGHT);
                } else {
                    contentAdapter = new HouseRentingShowListAdapter(null);
                    contentAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_RIGHT);
                    recyclerView.setAdapter(contentAdapter);
                }

                refreshLayout.setEnableRefresh(false);

                refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
                    @Override
                    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                        houseParmarBean.setPage(houseParmarBean.getPage() + 1);
                        mPresenter.listHouseRentByStore(isShowMyStore, houseParmarBean);
                    }
                });

                if (isShowMyStore) {
                    if (!mhouseRentListShowInfoBeans.isEmpty()) {
                        mystoryRenthouseAdapter.setNewData(mhouseRentListShowInfoBeans);
                        return;
                    }
                } else {
                    if (!mhouseRentListShowBeans.isEmpty()) {
                        contentAdapter.setNewData(mhouseRentListShowBeans);
                        return;
                    }
                }
                mPresenter.listHouseRentByStore(isShowMyStore, houseParmarBean);

                break;
            case -1:
                dropDownMenu.visible(false);
                if (mystory_content_lay.getChildCount() > 0) {
                    mystory_content_lay.removeAllViews();
                }
                break;
            case 1:
                llHeadTypeSelectLayout.setVisibility(View.GONE);
                dropDownMenu.visible(false);
                View view = LayoutInflater.from(this).inflate(R.layout.mystore_story, null);
                if (mystory_content_lay.getChildCount() > 0) {
                    mystory_content_lay.removeAllViews();
                }
                mystory_content_lay.addView(view);
                if (mmyStoreMainBean == null) {
                    showMessage("未获取到店铺信息");
                    return;
                }
                MyStoryHold myStoryHold = new MyStoryHold(view);
                myStoryHold.mystoreStoryDpmc.setText(mmyStoreMainBean.getStoreName());
                myStoryHold.mystoreStoryDplx.setText(mmyStoreMainBean.getStoreTypeName());
                myStoryHold.mystoreStoryLxdh.setText(AppUtil.mobil(mmyStoreMainBean.getStoreMobile()));
                String temShow="";
                if ((mmyStoreMainBean.getPassport() != null && !TextUtils.isEmpty(mmyStoreMainBean.getPassport()))||((mmyStoreMainBean.getIdCardFront() != null && !TextUtils.isEmpty(mmyStoreMainBean.getIdCardFront()) && mmyStoreMainBean.getIdCardReverseSide() != null && !TextUtils.isEmpty(mmyStoreMainBean.getIdCardReverseSide()))))
                {
                    temShow="身份认证";
                }
                if (mmyStoreMainBean.getBusinessLicense()!=null&&!TextUtils.isEmpty(mmyStoreMainBean.getBusinessLicense()))
            {
                if (TextUtils.isEmpty(temShow))
                {
                    temShow="营业执照";
                }else {
                    temShow+="、营业执照";
                }
            }
            if (TextUtils.isEmpty(temShow))
            {
                temShow="无";
            }
                myStoryHold.mystoreStoryRzlx.setText(temShow);
                myStoryHold.mystoreStoryXxdz.setText(mmyStoreMainBean.getAddressDetail());
                myStoryHold.mystoreStoryKdsj.setText(mmyStoreMainBean.getCreateTime().substring(0,10));
                myStoryHold.mystoreStoryJjExpandableTextView7.setOriginalText(mmyStoreMainBean.getStoreDetail());
                if (mmyStoreMainBean.getBusinessLicense()==null||TextUtils.isEmpty(mmyStoreMainBean.getBusinessLicense()))
                {
                    myStoryHold.mystoreStoryYyzzLay.setVisibility(View.GONE);
                 return;
                }
                getMglideImage().loadImage(this, ImageConfigImpl.builder().url(mmyStoreMainBean.getBusinessLicense())
                        .imageView(myStoryHold.mystoreStoryYyzzImg)
                        .build());
                myStoryHold.mystoreStoryYyzzImg.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        List<String> temPaths=new ArrayList<>();
                        temPaths.add(mmyStoreMainBean.getBusinessLicense());
                        AppUtil.lookBigImg(MyStoreActivity.this,mmyStoreMainBean.getBusinessLicense(),temPaths);
                    }
                });
                break;
        }
    }

    public static class MyStoryHold {

        @BindView(R.id.mystore_story_dpmc)
        TextView mystoreStoryDpmc;
        @BindView(R.id.mystore_story_dplx)
        TextView mystoreStoryDplx;
        @BindView(R.id.mystore_story_lxdh)
        TextView mystoreStoryLxdh;
        @BindView(R.id.mystore_story_rzlx)
        TextView mystoreStoryRzlx;
        @BindView(R.id.mystore_story_xxdz)
        TextView mystoreStoryXxdz;
        @BindView(R.id.mystore_story_kdsj)
        TextView mystoreStoryKdsj;
        @BindView(R.id.mystore_story_yyzz_img)
        ImageView mystoreStoryYyzzImg;
        @BindView(R.id.mystore_story_jj_ExpandableTextView7)
        ExpandableTextView mystoreStoryJjExpandableTextView7;
        @BindView(R.id.mystore_story_yyzz_lay)
        LinearLayout mystoreStoryYyzzLay;

        public MyStoryHold(View view) {
//            R.layout.mystore_story
            ButterKnife.bind(this, view);
        }
    }

    /**
     * 开始定位
     *
     * @return
     */
    public Location startLocation() {
        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        // Criteria是一组筛选条件
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        //设置定位精准度
        criteria.setAltitudeRequired(false);////设置是否可以定位海拔,如果设置定位海拔，返回一定是gps
        //是否要求海拔
        criteria.setBearingRequired(true);
        //是否要求方向
        criteria.setCostAllowed(true);
        //是否要求收费
        criteria.setSpeedRequired(true);
        //是否要求速度
        criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
        //设置电池耗电要求
        criteria.setBearingAccuracy(Criteria.ACCURACY_HIGH);
        //设置方向精确度
        criteria.setSpeedAccuracy(Criteria.ACCURACY_HIGH);
        //设置速度精确度
        criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
        //设置水平方向精确度
        criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
        //设置垂直方向精确度
        Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
        return location;
    }

    @Override
    public void getMemberLevelByUserSuccess(MemberCenterUserInfoBean mmemberCenterUserInfoBean) {
        memberCenterUserInfoBean = mmemberCenterUserInfoBean;
        if (mmemberCenterUserInfoBean.getMemberLevel().getLevelType() == 0) {
            mystoreHeadTogoUpdate.setText("去升级");
        } else {
            mystoreHeadTogoUpdate.setText("去续费");
        }
        getMglideImage().loadImage(this, ImageConfigImpl.builder().url(mmemberCenterUserInfoBean.getMemberLevel().getHeadImage())
                .imageView(mystoreHeadHydjImg)
                .build());

    }
}
